#!/bin/bash
if command -v gpio >/dev/null 2>&1; then 

if [ ! -f "/lib/libjgpio.so" ]; then
    echo "未发现动态链接库"
    #编译.o
    echo "build .o"
    gcc -Wall -fPIC -c clib/gpio.c -I ./ -I $JAVA_HOME/include/linux/ -I $JAVA_HOME/include/ -lwiringPi -lpthread

    #编译动态链接库
    echo "build .so"
    gcc -shared -o libjgpio.so gpio.o -lwiringPi -lpthread
    mv libjgpio.so /lib/libjgpio.so
fi

#编译java
echo "build java app"
javac -cp ./gpio-jar/gpio.jar: main.java

echo "=================START================="
java -cp ./gpio-jar/gpio.jar: main

else
    echo "请先安装wiringOP : https://github.com/orangepi-xunlong/wiringOP"
    exit;
fi
